#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef unsigned long long ull;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=4e5+5;
int n,m,k,c[N];
pii b[N];
bool flag;

void print() {
  rep(i,1,k) if(flag) swap(b[i].fi,b[i].se);
  printf("%lld\n",k);
  rep(i,1,k) printf("%lld %lld\n",b[i].fi,b[i].se);
}
void chk() {
  rep(i,1,k) assert(1<=b[i].fi&&b[i].fi<=n);
  rep(i,1,k) assert(1<=b[i].se&&b[i].se<=m);
  rep(i,1,k) c[i]=b[i].fi-b[i].se;
  sort(c+1,c+k+1);
  rep(i,2,k) assert(c[i]!=c[i-1]);
  rep(i,1,k) c[i]=b[i].fi+b[i].se;
  sort(c+1,c+k+1);
  rep(i,2,k) assert(c[i]!=c[i-1]);
}
void work() {
  n=read(), m=read();
  if(n>m) swap(n,m), flag=1;
  if(n==1) {
    k=m; rep(i,1,k) b[i]=pii(1,i);
  } else if(n==m) {
    k=2*n-2; int t=0;
    rep(i,1,m) b[++t]=pii(1,i);
    rep(i,2,m-1) b[++t]=pii(n,i);
  } else if(n%2==1) {
    k=n+m-1; int t=0;
    rep(i,1,n) b[++t]=pii(i,1);
    rep(i,1,n) b[++t]=pii(i,m);
    rep(i,(n+1)/2+1,m-(n+1)/2) b[++t]=pii((n+1)/2,i);
  } else {
    if(m%2==0) m--; k=n+m-1; int t=0;
    rep(i,1,n) b[++t]=pii(i,1);
    rep(i,1,n) b[++t]=pii(i,m);
    for(int i=n/2+2;i<=m-(n/2+1);i+=2) {
      b[++t]=pii(n/2,i), b[++t]=pii(n/2+1,i);
    }
  }
  if(flag) swap(n,m);
  print();
  chk();
}

signed main() {
  freopen("bishop.in","r",stdin);
  freopen("bishop.out","w",stdout);
  int T=1; while(T--) work();
  return 0;
}